// index.js

const api = require("../../utils/request");

// 获取应用实例
const app = getApp()

Page({
  data: {
    slideButtons: [
      {
        type: 'warn',
        text: '预约',
      }
    ],
    list: [],
    showActionsheet: false,
    groups: [
      { text: '示例菜单', value: 1 },
      { text: '示例菜单', value: 2 },
      { text: '负向菜单', type: 'warn', value: 3 }
    ]
  },
  slideButtonTap(e) {
    const { code } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/bracelet-borrow/borrow-form/borrow-form?code=${code}`,
    })
  },
  onShow() {
    this.fetchData()
  },
  fetchData() {
    api.get('/bracelet-borrow/bracelet-list', {})
      .then((res) => {
        if(res.code === '0') {
          const list = res.data.map((item) => {
            switch (item.status) {
              case 0:
                item.desc = '空闲'
                break;
              case 1:
                item.desc = '已预约'
                break;
              case 2:
                item.desc = '已借出'
                break;
              default:
                item.desc = ''
                break;
            }
            return item;
          })
          this.setData({
            list
          })
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
          wx.setNavigationBarTitle({
            title: '手环借阅'
          });
        }
      })
  },
  onPullDownRefresh() {
    wx.setNavigationBarTitle({
      title: '刷新中'
    })
    wx.showNavigationBarLoading()
    this.fetchData()
  },
})
